package com.ruoyi.web.controller.play;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.play.domain.PlayCopyright;
import com.ruoyi.play.domain.PlayCopyrightIO;
import com.ruoyi.play.domain.PlayCopyrightVO;
import com.ruoyi.play.service.IPlayCopyrightService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 片单版权Controller
 *
 * @author ruoyi
 * @date 2025-11-20
 */
@RestController
@RequestMapping("/play/copyright")
public class PlayCopyrightController extends BaseController {
    @Autowired
    private IPlayCopyrightService playCopyrightService;

    /**
     * 查询片单版权列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PlayCopyrightIO params) {
        startPage();
        List<PlayCopyrightVO> list = playCopyrightService.selectPlayCopyrightListTwo(params);
        return getDataTable(list);
    }

    /**
     * 导出片单版权列表
     */
    @Log(title = "片单版权", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlayCopyright playCopyright) {
        List<PlayCopyright> list = playCopyrightService.selectPlayCopyrightList(playCopyright);
        ExcelUtil<PlayCopyright> util = new ExcelUtil<PlayCopyright>(PlayCopyright.class);
        util.exportExcel(response, list, "片单版权数据");
    }

    /**
     * 获取片单版权详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(playCopyrightService.selectPlayCopyrightById(id));
    }

    /**
     * 新增片单版权
     */
    @Log(title = "片单版权", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlayCopyright playCopyright) {
        return toAjax(playCopyrightService.insertPlayCopyright(playCopyright));
    }

    /**
     * 修改片单版权
     */
    @Log(title = "片单版权", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlayCopyright playCopyright) {
        return playCopyrightService.updatePlayCopyright(playCopyright);
    }

    /**
     * 删除片单版权
     */
    @Log(title = "片单版权", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(playCopyrightService.deletePlayCopyrightByIds(ids));
    }

}
